public class CaseProductAccount {
	//anti-recursion classes
	private static boolean alreadyEnforcedAccount = false;
    public static boolean hasAlreadyEnforcedAccount() 
    {
    	return alreadyEnforcedAccount;
    }
    public static void setAlreadyEnforcedAccount() 
    {
    	alreadyEnforcedAccount = true;
    }
    //end anti-recursion classes
    
	//This class is designed to ensure the case Account is always the correct account associated. 
	//The class will be called by an after update, after insert case trigger.
	public static void enforceProductAccount(case[] cases)
	{
		if (!CaseProductAccount.hasAlreadyEnforcedAccount()) 
		{
			List<case> updateCases = new List<case>();
			Set<id> caseIdSet = New Set<id>();
			system.debug(cases);
			for (integer i = 0; i < cases.size(); i++)
			{
				if(Cases[i].Software_Product__c != Null)
				{
					caseIdSet.add(cases[i].id);			
				}	
			}
			if (caseIdSet.size()>0)
			{
				for(case c : [select accountId,Software_Product__c,Software_Product__r.Account__c,Software_Product__r.Account__r.Name from case where id in :caseIdSet])
				{
					if (c.AccountId != c.Software_Product__r.Account__c)if(c.Software_Product__r.Account__r.Name != 'Account Not Verified')
					{
						c.AccountId = c.Software_Product__r.Account__c;
						updateCases.add(c);
					}
				}
				update updateCases;
				setAlreadyEnforcedAccount();
			}
		}	
	
	}

}